package com.martin.fastframe.ui.page.index

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.martin.fastframe.R
import com.martin.fastframe.databinding.ActivityPageIndexBinding
import com.martin.lib_base.base.BaseActivity
import com.martin.lib_base.common.CommonVP2Adapter
import com.martin.lib_base.impl.EmptyViewModel

class PageIndexActivity : BaseActivity<ActivityPageIndexBinding,EmptyViewModel>() {

    override fun getViewModelClass() = EmptyViewModel::class.java

    override fun layoutId() = R.layout.activity_page_index

    override fun initOnCreate(savedInstanceState: Bundle?) {
        binding.vp.adapter = CommonVP2Adapter(
            listOf(
                EmptyFragment(),
                EmptyFragment(),
                EmptyFragment(),
            ), supportFragmentManager, lifecycle
        )

        binding.piv.pageCount = 3
        binding.piv.index = 0

        binding.vp.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                binding.piv.index = position
            }
        })
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, PageIndexActivity::class.java)
            context.startActivity(starter)
        }
    }
}